package com.example.myapplication.Services;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import com.example.myapplication.BroadcastTest.BroadcastTestActivity;
import com.example.myapplication.ContentTest.ContentActivity;
import com.example.myapplication.DataBase.DataStoreActivity;
import com.example.myapplication.MainActivity;
import com.example.myapplication.R;

public class ServicesTestActivity extends AppCompatActivity {
  @Override protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.services_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Services实验");
    setSupportActionBar(toolbar);
    Init();
  }

  private void Init() {
    Button localButton = (Button) findViewById(R.id.local_button);
    Button musicButton = (Button) findViewById(R.id.music_button);
    localButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToLocalActivity();
      }
    });
    
    musicButton.setOnClickListener(new View.OnClickListener() {
      @Override public void onClick(View v) {
        JumpToMusicActivity();
      }
    });
  }

  private void JumpToMusicActivity() {
    Intent intent = new Intent(this, MusicActivity.class);
    startActivity(intent);

  }

  private void JumpToLocalActivity() {
    Intent intent = new Intent(this, LocalServicesActivity.class);
    startActivity(intent);

  }

  @Override public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 1, 0, "返回上一个Activity");
    menu.add(0, 2, 1, "转到下一个Activity");
    return true;
  }

  @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    switch (item.getItemId()) {
      case 1:
        BackToLastActivity();
        break;
      case 2:
        GoToNextActivity();
        break;
    }
    return true;
  }

  private void GoToNextActivity() {
    Intent intent = new Intent(this, BroadcastTestActivity.class);
    startActivity(intent);
  }
  private void BackToLastActivity() {
    Intent intent = new Intent(this, ContentActivity.class);
    startActivity(intent);

  }
}
